#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "AppDelegate.h"
#import "dfhgwhruebvhrheylatentagony.h"
#import "dfhgwhruebvhrheycreepvacation.h"
#import "dfhgwhruebvhrheyfertilebasement.h"
#import "dfhgwhruebvhrheycandidateroutineViewController.h"
#import "dfhgwhruebvhrheyaltererroneousViewController.h"
@interface dfhgwhruebvhrheyaltererroneousViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UITableView *tabIV;
@property (nonatomic, strong) dfhgwhruebvhrheycreepvacation *placeholder;
@property (nonatomic, strong) NSMutableArray<PPP_RecordItemModel *> *dataArray;
@end
static NSString *cellIdentifier = @"historyCell";
@implementation dfhgwhruebvhrheyaltererroneousViewController
- (dfhgwhruebvhrheycreepvacation *)placeholder {
	if (_placeholder == nil) {
		_placeholder = [[NSBundle mainBundle] loadNibNamed:@"dfhgwhruebvhrheycreepvacation" owner:nil options:nil].firstObject;
	}
	return _placeholder;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
}
- (void)loadUI {
	self.dataArray = [@[] mutableCopy];
	self.view.backgroundColor = [UIColor clearColor];
	self.topView.layer.cornerRadius = 10;
	self.topView.layer.masksToBounds = YES;
	self.topView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner;
	self.tabIV.separatorStyle = UITableViewCellSeparatorStyleNone;
	[self.tabIV registerNib:[UINib nibWithNibName:@"dfhgwhruebvhrheyfertilebasement" bundle:nil] forCellReuseIdentifier:cellIdentifier];
	self.placeholder.hidden = YES;
	[self.view addSubview:self.placeholder];
	AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
	if (delegate.status == AFNetworkReachabilityStatusNotReachable) {
		[self configurePlaceHolder:1];
	}
}
- (void)configurePlaceHolder:(int)type {
	self.placeholder.hidden = NO;
	__weak typeof(self) weakSelf = self;
	if (type == 1) {
		self.placeholder.iconName = @"net_unavaiable";
		self.placeholder.placeholder = @"Content retrieval failed, click to reload.";
		[self.placeholder placeholder:@"Reload" andAction:^{
			__strong typeof(weakSelf) strongSelf = weakSelf;
			[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
			[strongSelf loadData:^{
				[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
			}];
		}];
	}else {
		self.placeholder.iconName = @"no_data";
		self.placeholder.placeholder = @"No historical information";
		[self.placeholder placeholder:@"Get Loan" andAction:^{
			__strong typeof(weakSelf) strongSelf = weakSelf;
			dfhgwhruebvhrheycandidateroutineViewController *tabBar = (dfhgwhruebvhrheycandidateroutineViewController *)[dfhgwhruebvhrheyoptionsaving.keyWindow rootViewController];
			tabBar.selectedIndex = 0;
			[strongSelf.navigationController popToRootViewControllerAnimated:YES];
		}];
	}
}
- (void)loadData:(void (^)(void))result {
	__weak typeof(self) weakSelf = self;
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwlambbreast path:loadRecordApi isEncrypt:YES withParams:nil success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		dfhgwhruebvhrheylatentagony *model = [dfhgwhruebvhrheylatentagony yy_modelWithJSON:json];
		if (model.code == 200) {
			for (PPP_RecordItemModel *item in model.data) {
				[strongSelf.dataArray addObject:item];
			}
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
		strongSelf.placeholder.hidden = YES;
		if (strongSelf.dataArray.count == 0) {
			[strongSelf configurePlaceHolder:0];
		}
		if (result) {
			result();
		}
		[strongSelf.tabIV reloadData];
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf configurePlaceHolder:1];
		if (result) {
			result();
		}
	}];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
	CGFloat radius = 10;
	CGRect bounds = cell.bounds;
	UIBezierPath *bezierPath = nil;
	CAShapeLayer *radiusLayer = [CAShapeLayer layer];
	NSInteger rows = [tableView numberOfRowsInSection:indexPath.section];
	if (indexPath.row == rows - 1) {
		bezierPath = [UIBezierPath bezierPathWithRoundedRect:bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(radius, radius)];
	}
	radiusLayer.path = bezierPath.CGPath;
	radiusLayer.fillColor = [UIColor whiteColor].CGColor;
	UIView *bgView = [[UIView alloc] initWithFrame:bounds];
	bgView.backgroundColor = [UIColor clearColor];
	[bgView.layer insertSublayer:radiusLayer atIndex:0];
	cell.backgroundView = bgView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	return self.dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	dfhgwhruebvhrheyfertilebasement *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
	cell.selectionStyle = UITableViewCellSelectionStyleNone;
	[cell bindData:self.dataArray[indexPath.row]];
	return cell;
}
@end
